<?
	include "../config/constants.php";

	if(!$_POST[_pid])
	{	
		echo "ERROR";
		exit;
	}

	$pid = $_POST[_pid];

	$mysqli=mysqli_connect("localhost", "canss", "1022", "contentsmetadata_db") or die("Could not connect: ".mysql_error());
	mysqli_query($mysqli, "SET NAMES 'utf8'");
	
	$query1 = "DELETE FROM `contentsmetadata_db`.`tblPID` WHERE `pid`='$pid';";
	$query2 = "DELETE FROM `contentsmetadata_db`.`tblPerson` WHERE `tblPID_pid`='$pid';";
	$query3 = "DELETE FROM `contentsmetadata_db`.`tblChannel` WHERE `tblPID_pid`='$pid';";
	$query4 = "DELETE FROM `contentsmetadata_db`.`tblContentsChannelHolds` WHERE `tblChannel_tblPID_pid`='$pid';";
	$query5 = "DELETE FROM `contentsmetadata_db`.`tblFeed` WHERE `tblPID_pid`='$pid';";
	$query6 = "DELETE FROM `contentsmetadata_db`.`tblLinkage` WHERE `tblPID_pid`='$pid';";
	$query8 = "DELETE FROM `contentsmetadata_db`.`tblPersonDescription` WHERE `tblPID_pid`='$pid';";

    if( $query6 && mysqli_query( $mysqli, $query6 ) != 1 )
    {echo "ERROR: Fail to delete from MDB6".$query6;}

    if( $query5 && mysqli_query( $mysqli, $query5 ) != 1 )
    {echo "ERROR: Fail to delete from MDB5".$query5;}

    if( $query4 && mysqli_query( $mysqli, $query4 ) != 1 )
    {echo "ERROR: Fail to delete from MDB4".$query4;}

    if( $query3 && mysqli_query( $mysqli, $query3 ) != 1 )
    {echo "ERROR: Fail to delete from MDB3".$query3;}

	if( $query8 && mysqli_query( $mysqli, $query8 ) != 1 )
	{echo "ERROR: Fail to delete from MDB8".$query8;}

    if( $query2 && mysqli_query( $mysqli, $query2 ) != 1 )
    {echo "ERROR: Fail to delete from MDB2".$query2;}

    if( $query1 && mysqli_query( $mysqli, $query1 ) != 1 )
    {echo "ERROR: Fail to delete from MDB".$query1;}

	// yet, we do not delete contents which belongs to pid.

	if($_POST[_rurl])
	{
		$rurl = $_POST[_rurl];
		header( "Location: http://portal.canss.net/$rurl" );
	}
?>
